<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        *{
            padding:0;
            margin:0;
            list-style: none;
        }
        .tab{
            width:300px;
            height:300px;
            border:1px solid red;
            margin:100px auto;
        }
        .tab input{
            width:100px;
            height:30px;
            float:left;
        }
        .tab .active{
            background: paleturquoise;
            color:#fff;
        }
        .tab li{
            width:300px;
            height:270px;
            background: purple;
            font-size: 30px;
            color:#fff;
            text-align: center;
            line-height: 270px;
            display: none;
        }
        .tab .show{
            display: block;
        }
        .tab section{
            overflow: hidden;
        }
    </style>
    <script>
        class Tab{
            constructor(id){
                //属性
                this.parent=document.querySelector(id);
                this.aBtn=this.parent.querySelectorAll('input');
                this.aLi=this.parent.querySelectorAll('li');
                //初始化事件
                this.show();
            }
            show(){
                let _this=this;
                for(let i=0; i<this.aBtn.length;i++){
                    this.aBtn[i].onclick=function(){
                        _this.index=i;
                        _this.fn(i);
                    };
                }
            }
            fn(i){
                console.log(this);//自动转向对象本身
                for(var j=0;j<this.aLi.length;j++){
                    this.aBtn[j].className='';
                    this.aLi[j].className='';
                }
                this.aLi[i].className='show';
                this.aBtn[i].className='active';
            }
        }

        //继承Tab
        class AutoplayTab extends Tab{
            constructor(id){
                //继承属性
                super(id);
                this.autoFn();
                this.index=0;
            }
            //添加方法
            autoFn(){
                var _this=this;
                setInterval(function(){
                    _this.index++;
                    if(_this.index==_this.aBtn.length){
                        _this.index=0;
                    }
                    _this.fn(_this.index);
                },1000);
            }
        }
        window.onload=function(){
            //调用自动播放的方法
            new AutoplayTab("#tab1");
        }
    </script>
</head>
<body>
<div class="tab" id="tab1">
    <section class="btnBox">
        <input type="button" value="按钮1" class="active">
        <input type="button" value="按钮2">
        <input type="button" value="按钮3">
    </section>
    <ul>
        <li class="show">1</li>
        <li>2</li>
        <li>3</li>
    </ul>
</div>
</body>
</html>